<!--
 * @Date: 2020-01-06 09:28:29
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2020-06-03 09:42:08
 * @describe: -收到的提醒-
 -->
<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-sys__sysremind}">
      <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
        <el-form-item>
          <el-input v-model="dataForm.id" placeholder="id" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-button @click="getDataList()">{{ $t('query') }}</el-button>
        </el-form-item>
        <!-- <el-form-item>
          <el-button type="info" @click="exportHandle()">{{ $t('export') }}</el-button>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="addOrUpdateHandle()">{{ $t('add') }}</el-button>
        </el-form-item>
        <el-form-item>
          <el-button
            v-if="$hasPermission('sys:sysremind:delete')"
            type="danger"
            @click="deleteHandle()"
          >{{ $t('deleteBatch') }}</el-button>
        </el-form-item>-->
      </el-form>
      <el-table
        v-loading="dataListLoading"
        :data="dataList"
        border
        @selection-change="dataListSelectionChangeHandle"
        style="width: 100%;"
      >
        <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
        <el-table-column prop="id" label="ID" header-align="center" align="center" width="130">
          <template slot-scope="scope">
            <el-button
              type="text"
              @click="goList(scope.row)"
            >{{(scope.row.type==1?"KY - ":"FY - ")+scope.row.moduleId.substring(scope.row.moduleId.length-6)}}</el-button>
          </template>
        </el-table-column>
        <el-table-column prop="type" label="类型" header-align="center" align="center" width="80">
          <template slot-scope="scope">{{$getDictLabel("sysModuleType", scope.row.type)}}</template>
        </el-table-column>
        <el-table-column prop="content" label="提醒内容" header-align="center" align="center"></el-table-column>
        <el-table-column prop="state" label="状态" header-align="center" align="center" width="80">
          <template slot-scope="scope">
            <el-tooltip
              v-if="scope.row.state==3"
              :content="scope.row.reject"
              placement="top"
              effect="light"
            >
              <span>{{$getDictLabel("sysRemindState",scope.row.state)}}</span>
            </el-tooltip>
            <span v-else>{{$getDictLabel("sysRemindState",scope.row.state)}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="solve" label="是否解决" header-align="center" align="center" width="80">
          <template slot-scope="scope">
            <el-switch
              v-model="scope.row.solve"
              @change="tabSolveChange(scope.row)"
              :active-value="1"
              :inactive-value="0"
            ></el-switch>
          </template>
        </el-table-column>
        <el-table-column
          prop="userName"
          label="接收人"
          header-align="center"
          align="center"
          width="100"
        ></el-table-column>
        <el-table-column
          prop="oldUserName"
          label="原归属人"
          header-align="center"
          align="center"
          width="120"
        ></el-table-column>
        <el-table-column
          prop="creatorName"
          label="发送人"
          header-align="center"
          align="center"
          width="120"
        ></el-table-column>
        <el-table-column
          prop="deptName"
          label="发送人部门"
          header-align="center"
          align="center"
          width="120"
        ></el-table-column>
        <el-table-column
          prop="createDate"
          label="发送时间"
          header-align="center"
          align="center"
          width="180"
        ></el-table-column>
        <el-table-column
          :label="$t('handle')"
          fixed="right"
          header-align="center"
          align="center"
          width="150"
        >
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="ViewHandle(scope.row.id)">查看</el-button>
            <el-button type="text" size="small" @click="RejectClick(scope.row.id)">驳回</el-button>
            <el-button
              v-if="$hasPermission('sys:sysremind:delete')"
              type="text"
              size="small"
              @click="deleteHandle(scope.row.id)"
            >{{ $t('delete') }}</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="ZWbox"></div>
      <div class="paginationBox">
        <el-pagination
          :current-page="page"
          :page-sizes="[10, 20, 50, 100]"
          :page-size="limit"
          :total="total"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="pageSizeChangeHandle"
          @current-change="pageCurrentChangeHandle"
        ></el-pagination>
      </div>
      <!-- 查看弹窗 -->

      <el-dialog :visible.sync="ViewdataFormvisible" title="查看" :destroy-on-close="true">
        <el-form
          :model="ViewdataForm"
          ref="ViewdataForm"
          :label-width="$i18n.locale === 'en-US' ? '120px' : '100px'"
          class="svgColor4"
        >
          <el-form-item label="提醒内容：">{{ViewdataForm.content}}</el-form-item>
          <br />
          <el-divider></el-divider>
          <el-form-item label="编号：">
            <el-button
              type="text"
              @click="goList(ViewdataForm)"
            >{{(ViewdataForm.type=='1'?"KY - ":"FY - ")+ViewdataForm.moduleId.substring(ViewdataForm.moduleId.length-6)}}</el-button>
          </el-form-item>
          <el-form-item label="发送人：">{{ViewdataForm.creatorName}}</el-form-item>
          <el-form-item label="发送人部门：">{{ViewdataForm.deptName}}</el-form-item>
          <el-form-item label="发送时间：">{{ViewdataForm.createDate}}</el-form-item>
          <el-form-item label="接收人：">{{ViewdataForm.userName}}</el-form-item>
        </el-form>
      </el-dialog>
      <!-- 驳回弹窗 -->
      <el-dialog title="驳回" :visible.sync="RejectHandle" width="30%">
        <el-form :model="Rejectform">
          <el-form-item label="驳回原因">
            <el-input v-model="Rejectform.reject" autocomplete="off" type="textarea"></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="RejectHandle = false">取 消</el-button>
          <el-button type="primary" @click="RejectFun">确 定</el-button>
        </div>
      </el-dialog>
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from "@/mixins/view-module";
export default {
  mixins: [mixinViewModule],
  data() {
    return {
      mixinViewModuleOptions: {
        getDataListURL: "/sys/sysremind/receivePage",
        getDataListIsPage: true
      },
      dataForm: {
        id: this.$route.query.ID ? this.$route.query.ID : ""
      },
      ViewdataFormvisible: false,
      ViewdataForm: {
        moduleId: ""
      },
      RejectHandle: false,
      Rejectform: {
        reject: "",
        id: ""
      }
    };
  },
  created() {},
  components: {
    // AddOrUpdate
  },
  methods: {
    //查看提醒详情
    ViewHandle(id) {
      this.$http
        .get(`/sys/sysremind/${id}`)
        .then(({ data: res }) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg);
          }
          this.ViewdataForm = res.data;
          this.ViewdataFormvisible = true;
          this.$store.commit("getReceiveNum");
        })
        .catch(() => {});
    },
    //跳转到列表页
    goList(row) {
      if (row.type == 2) {
        this.$router.push({
          name: "house-houseinfo",
          query: {
            moduleId: row.moduleId
          }
        });
      } else if (row.type == 1) {
        this.$router.push({
          name: "customer-customerhouseinfo",
          query: {
            moduleId: row.moduleId
          }
        });
      }
    },
    //点击驳回
    RejectClick(id) {
      this.Rejectform = {
        reject: "",
        id: id
      };
      this.RejectHandle = true;
    },
    //驳回
    RejectFun() {
      let _this = this;
      this.$http
        .post(`/sys/sysremind/reject`, this.Rejectform)
        .then(({ data: res }) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg);
          }
          this.$message.success("已驳回");
          this.RejectHandle = false;
          this.getDataList();
        })
        .catch(() => {});
    },
    //是否已解决
    tabSolveChange(row) {
      let _this = this;
      this.$http
        .put(
          `/sys/sysremind/updateSolve`,
          {},
          {
            params: {
              id: row.id,
              solve: row.solve
            }
          }
        )
        .then(({ data: res }) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg);
          }
          this.$message.success("已解决！");
        })
        .catch(() => {});
    }
  }
};
</script>
